/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package backupit.core.io;

import backupit.core.dirbackup.DirBackupConsoleReport;
import backupit.core.report.Report;
import backupit.core.report.ReportManager;
import backupit.core.report.ReportQueue;
import java.beans.XMLEncoder;
import java.io.BufferedOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author dbotelho
 */
public class SaveReportQueue implements Runnable{
    
    private ReportQueue reportQueue;
    private XMLEncoder encoder;

    public SaveReportQueue(String fileName,ReportQueue reportQueue) throws FileNotFoundException{
        super();
        this.reportQueue = reportQueue;
        this.encoder = new XMLEncoder(new BufferedOutputStream(new FileOutputStream(fileName)));
    }

    public void run() {
        encoder.writeObject(reportQueue);
        encoder.close();
    }

    public static void main(String[] args){
        try {
            ReportQueue r = new ReportQueue();
            r.add(new DirBackupConsoleReport());
            new Thread(new SaveReportQueue("/home/dbotelho/backuplist.xml", r)).start();
        } catch (FileNotFoundException ex) {
            Logger.getLogger(SaveBackupList.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
